#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT(lingua-franca-beta, 0.2, lf-bugs@gmail.com)
AM_INIT_AUTOMAKE(lingua-franca-beta,0.2,lf-bugs@gmail.com)
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADER([config.h])

dnl Add the languages which your application supports here.
ALL_LINGUAS=""
AM_GLIB_GNU_GETTEXT

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL
AM_PROG_CC_C_O

# Checks for header files.C_SUBST(PURPLE_CFLAGS)
AC_HEADER_STDC
AC_CHECK_HEADERS([libintl.h stdlib.h string.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([strdup])

GETTEXT_PACKAGE=lingua-franca
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [lingua-franca])

PACKAGE=lingua-franca
AC_SUBST(PACKAGE)
AC_DEFINE_UNQUOTED(PACKAGE,"$PACKAGE", [lingua-franca])


dnl #######################################################################
dnl # Check for GLib 2.0 (required)
dnl #######################################################################
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.0.0 gobject-2.0 gmodule-2.0 gthread-2.0], , [
        AC_MSG_RESULT(no)
        AC_MSG_ERROR([

You must have the GLib 2.0 development headers installed to build.
])])
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

AC_ARG_WITH(x, [],
        with_x="$withval", with_x="yes")
AC_ARG_ENABLE(gtkui, [AC_HELP_STRING([--disable-gtkui],
                [compile without GTK+ user interface])],
        enable_gtkui="$enableval", enable_gtkui="yes")
AC_ARG_ENABLE(consoleui, [AC_HELP_STRING([--disable-consoleui],
                [compile without console user interface])],
        enable_consoleui=$enableval, enable_consoleui=yes)

dnl #######################################################################
dnl # Check for GTK 2.0 (required)
dnl #######################################################################
PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.0.0], , [
                AC_MSG_RESULT(no)
                AC_MSG_ERROR([

You must have the GTK+ 2.0 installed for configuration UI
])])
        AC_SUBST(GTK_CFLAGS)
        AC_SUBST(GTK_LIBS)


dnl #######################################################################
dnl # Check for LibXML2 (required)
dnl #######################################################################
PKG_CHECK_MODULES(LIBXML, [libxml-2.0 >= 2.6.0], , [
        AC_MSG_RESULT(no)
        AC_MSG_ERROR([

You must have libxml2 >= 2.6.0 development headers installed to build.
])])
AC_SUBST(LIBXML_CFLAGS)
AC_SUBST(LIBXML_LIBS)

dnl #######################################################################
dnl # check for curl ( required)
dnl #######################################################################

PKG_CHECK_MODULES(CURL, [libcurl >= 7.16.2], , [
        AC_MSG_RESULT(no)
        AC_MSG_ERROR([

You must have libcurl package for backend http post
])])
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)
dnl #######################################################################
dnl # Check for purple  , translation is a back end plugin
dnl # so purple is required , technically for development alone , pidgin
dnl # is not required ,although we check for both
dnl #######################################################################
PKG_CHECK_MODULES(PURPLE, purple,
[
        AC_DEFINE(HAVE_PURPLE, 1, [Define if we've found pidgin.])
        HAVE_PURPLE="yes"
        AM_CONDITIONAL(HAVE_PURPLE, true)
], [
        AC_MSG_RESULT([no])
        HAVE_PURPLE="no"
        AM_CONDITIONAL(HAVE_PURPLE, false)
])


if test x"$prefix" = x"NONE" ; then
        PURPLE_LIBDIR=`pkg-config --variable=libdir purple`
        PURPLE_DATADIR=`pkg-config --variable=datadir purple`
else
        PURPLE_LIBDIR="$libdir"
        PURPLE_DATADIR="$datadir"
fi

PURPLE_PIXMAPSDIR=""

# this is a hack but should work fine.
# we use the libpurple datadir for PP_LOCALEDIR since we are not breaking up
# the pot's yet, and need to make sure they goto the same place
PP_LOCALEDIR="PURPLE_DATADIR/locale"
AC_DEFINE_UNQUOTED(PP_LOCALEDIR, ["$PP_LOCALEDIR"], [The localedir to use])

if test x"$PURPLE_LIBDIR" != x"" ; then
        PURPLE_LIBDIR="$PURPLE_LIBDIR/purple-2"
fi

if test x"$PURPLE_DATADIR" != x"" ; then
        PURPLE_PIXMAPSDIR="$PURPLE_DATADIR/pixmaps/libpurple"
        AC_DEFINE_UNQUOTED(PURPLE_PIXMAPSDIR, "$PURPLE_PIXMAPSDIR", [Libpurple pixmaps directory])
fi

AC_SUBST(PURPLE_LIBS)
AC_SUBST(PURPLE_CFLAGS)
AC_SUBST(PURPLE_LIBDIR)
AC_SUBST(PURPLE_DATADIR)
AC_SUBST(PURPLE_PIXMAPSDIR)


dnl #######################################################################
dnl # Check for pidgin
dnl #######################################################################
PKG_CHECK_MODULES(PIDGIN, pidgin,
[
        AC_DEFINE(HAVE_PIDGIN, 1, [Define if we've found pidgin.])
        HAVE_PIDGIN="yes"
        AM_CONDITIONAL(HAVE_PIDGIN, true)
], [
        AC_MSG_RESULT([no])
        HAVE_PIDGIN="no"
        AM_CONDITIONAL(HAVE_PIDGIN, false)
])


if test x"$prefix" = x"NONE" ; then
        PIDGIN_LIBDIR=`pkg-config --variable=libdir pidgin`
        PIDGIN_DATADIR=`pkg-config --variable=datadir pidgin`
else
        PIDGIN_LIBDIR="$libdir"
        PIDGIN_DATADIR="$datadir"
fi

AC_SUBST(PIDGIN_CFLAGS)
AC_SUBST(PIDGIN_LIBS)
AC_SUBST(PIDGIN_LIBDIR)
AC_SUBST(PIDGIN_DATADIR)

AC_CONFIG_FILES([Makefile
		 lingua-franca.spec
                 src/pidgin/Makefile
                 src/lib/Makefile
                 src/lib/lf.pc
                 src/lib/lf-uninstalled.pc
		 test/Makefile])
AC_OUTPUT
dnl #######################################################################
dnl # Ouput!!
dnl #######################################################################
echo;
echo $PACKAGE $VERSION Configuration complete
echo;

echo Build pidgin plugins.............: $HAVE_PIDGIN
if test x"$HAVE_PIDGIN" = x"yes" ; then
        echo Installing pidgin plugins to.....: `eval eval echo $PIDGIN_LIBDIR`
        echo Installing pidgin plugin data to.: `eval eval echo $PIDGIN_DATADIR`
fi
echo;
